package com.thebitstream.sandy.support;

import java.util.ArrayList;

import org.red5.server.api.IConnection;
import org.red5.server.api.service.IPendingServiceCall;
import org.red5.server.api.service.IPendingServiceCallback;
import org.red5.server.api.service.IServiceCapableConnection;

import com.thebitstream.sandy.support.ClientData;

/**
 * @author Andy Shaules
 *
 */
public class Notify extends Thread implements IPendingServiceCallback {

	private IConnection _client;

	private Object[] _data;

	private Engine _calback;

	private ClientData _clientData;

	public ClientData getClientData(){
		return _clientData;
	}
	public Object[] getHeader(){
		return _data;
	}
	public Notify(IConnection client, Object[] capsule, Engine callback, ClientData clientData) {
		_calback = callback;
		_client = client;
		_data = capsule;
		_clientData = clientData;
	}

	@Override
	public void run() {
		((IServiceCapableConnection) _client).invoke("onSandy", new Object[] { _data }, this);
	}

	@SuppressWarnings("unchecked")
	@Override
	public void resultReceived(IPendingServiceCall call) {
		ArrayList<Object> ret = (ArrayList<Object>) call.getResult();

		_calback.onCallBack(_clientData, ret);
	}
}
